package echat.future.cn.echat.my.utils;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

/**
 * Created by 86936 on 2018/8/9.
 * 路由工具类
 * @QQ 869360026
 */
public class RouterHelper {

    public static String invalidActivityName = null;


    public static void init(String invalidActivityName){
        RouterHelper.invalidActivityName = invalidActivityName;
    }


    /**
     * 跳转到本地页面
     * @param context
     * @param intent
     * @param cls
     */
    public static void openActivity(Context context,Intent intent, String cls){
        try{
           intent.setClass(context, Class.forName(cls));
           context.startActivity(intent);
        }catch (ClassNotFoundException e) {
            ToastUtils.toastMsg(context,"路由未找到activity");
        }
    }

    /**
     * 跳转到登陆失效的页面
     * @param context
     */
    public static void toInvalidActivity(Context context){
            UserHelper.clean();
            if(invalidActivityName == null){
                ToastUtils.toastMsg(context,"没有设置默认的失效页面");
            }
            Intent intent = new Intent();
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            openActivity(context,intent,invalidActivityName);
    }

}
